<?php
namespace Home\Controller;
use Think\Controller;
use Think\Auth;
class CommonController extends Controller {
     function _initialize() {
        //载入导航
        $auto=new Auth;
          $rules='Admin/'.CONTROLLER_NAME.'/'.ACTION_NAME;
//        print_r($_SESSION);die;
// die;
        // if (!$auto->check($rules,$_SESSION['admin']['id'])) {
        //     $this->error('您目前没有权限访问，如需帮助请联系xxx');# code...
        // }
        $laynav=D('nav')->where('pid=0 and is_show=1 and is_home=1')->select();
        $this->assign('laynav',$laynav);
        $child_laynav=D('nav')->where('pid!=0 and is_show=1 and is_home=1')->select();
        $this->assign('child_laynav',$child_laynav);
        //动态实例化类对象
        //$this->Model=D(CONTROLLER_NAME);
    }
    //文件上传
    public function upload(){
        $data=array();
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->savePath  =      ""; // 设置附件上传目录// 上传文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            foreach($info as $file){
               $data[].= $file['savepath'].$file['savename'];
            }
            if(count($data)>1){
                return $data;
            }else{
                return $data[0];
            }


        }
    }
}